package com.owc.controller.admin;

import com.owc.domain.BaseResult;
import com.owc.domain.PageBean;
import com.owc.domain.dto.ProductDetailDTO;
import com.owc.domain.dto.admin.OrderListDTO;
import com.owc.domain.dto.admin.ProductWithAdminDTO;
import com.owc.domain.vo.admin.ProductAttachVo;
import com.owc.domain.vo.admin.ProductModel;
import com.owc.domain.vo.admin.ProductQueryVo;
import com.owc.service.admin.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * @Author xiaom
 * @Date 2020/2/28 13:40
 * @Version 1.0.0
 * @Description <>
 **/
@RestController
@RequestMapping(value = "/admin/product")
@Api(tags = "(manage-V2)产品管理")
public class ProductController {

    private final ProductService productService;

    public ProductController(ProductService productService) {
        this.productService = productService;
    }

    @PostMapping(value = "/add")
    @ApiOperation("新建产品")
    public BaseResult<Boolean> addProduct(@RequestBody @Valid ProductModel productModel){
        return BaseResult.success(productService.add(productModel));
    }

    @GetMapping(value = "/detail")
    @ApiOperation("获取产品详情")
    @ApiImplicitParam(name = "id",value = "产品ID")
    public BaseResult<ProductDetailDTO> detail(@RequestParam @NotNull(message = "产品ID不能为空") Long id){
        return BaseResult.success(productService.detail(id));
    }

    @PostMapping(value = "/update")
    @ApiOperation("修改扩展信息")
    public BaseResult<Boolean> update(@RequestBody @Valid ProductAttachVo productAttachVo){
        return BaseResult.success(productService.update(productAttachVo));
    }

    @PostMapping(value = "/list")
    @ApiOperation("获取产品列表")
    public BaseResult<PageBean<ProductWithAdminDTO>> list(@RequestBody ProductQueryVo productQueryVo){
        return BaseResult.success(productService.list(productQueryVo));
    }

    @GetMapping(value = "/getProductOrderList")
    @ApiOperation("获取产品下的订单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "产品ID"),
            @ApiImplicitParam(name = "pageIndex",value = "分页"),
            @ApiImplicitParam(name = "pageSize",value = "分页")
    })
    public BaseResult<OrderListDTO> getProductOrderList(@RequestParam @NotNull(message = "产品ID不能为空") Long id,
                                                        @RequestParam Integer pageIndex,
                                                        @RequestParam Integer pageSize){
        return productService.getProductOrderList(id,pageIndex,pageSize);
    }

}
